<!-- eslint-disable vue/require-valid-default-prop -->
<script setup>
import { toRefs } from 'vue'
import { oss } from '@/utils/config'
import { usePraise } from '@/hooks/usePraise.js'
import * as dayjs from 'dayjs'
const props = defineProps({
  list: { type: Object, default: {} }
})
const { list } = toRefs(props)
const emit = defineEmits(['show', 'remark'])
const onShow = () => {
  emit('show', list.value)
}
const onRemark = () => {
  emit('remark', list.value)
}
// 点赞
const onPraise = (e) => {
  console.log(e)
  if (list.value.isPraise === 0) {
    list.value.isPraise = 1
    list.value.praiseSum += 1
  } else {
    list.value.isPraise = 0
    list.value.praiseSum -= 1
  }
  usePraise({
    targetId: e.commentId,
    targetType: 3
  })
}
</script>
<template>
  <div class="v-remark-module">
    <van-image round width="2.2em" height="2.2em" :src="list.headImgUrl" />
    <div class="v-remark-module-right">
      <div class="v-remark-module-name">{{ list.nickName }}</div>
      <div class="v-remark-module-desc">
        {{ list.content }}
      </div>
      <div class="v-remark-module-bottom">
        <span>{{ dayjs(list.createTime).format('YYYY.MM.DD') }}</span>
        <p>
          <van-icon
            :name="oss + '/nutrition/web/%E8%AF%84%E8%AE%BA.png'"
            @click="onRemark"
          />
          <van-icon
            :class="{ 'v-praise-active': list.isPraise === 1 }"
            @click.stop="onPraise(list)"
            :name="
              oss +
              (list.isPraise === 1
                ? '/nutrition/web/%E7%82%B9%E8%B5%9E-active.png'
                : '/nutrition/web/%E7%82%B9%E8%B5%9E.png')
            "
          />
        </p>
      </div>
      <div
        class="v-remark-module-btn"
        v-if="list.isHasChild === 1"
        @click="onShow"
      >
        查看折叠评论
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.v-remark-module {
  padding: 10px 12px 0;
  display: flex;
  justify-content: space-between;
  position: relative;
  background: #ffffff;
  color: #212532;
  .v-remark-module-right {
    width: 306px;
    padding-bottom: 15px;
    position: relative;
    .v-remark-module-name {
      font-size: 14px;
      line-height: 30px;
    }
    .v-remark-module-desc {
      font-size: 14px;
      line-height: 21px;
    }
    .v-remark-module-bottom {
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: #848484;
      line-height: 30px;
      font-size: 13px;
      p {
        display: flex;
        align-items: flex-end;
        .van-icon {
          font-size: 15px;
          margin-left: 20px;
        }
      }
    }
    .v-remark-module-btn {
      margin-top: 6px;
      text-align: center;
      background: #f8f8f8;
      font-size: 13px;
      line-height: 30px;
      border-radius: 5px;
    }
    &::after {
      content: '';
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 1px;
      background: #f8f8f8;
      transform: scaleY(0.5);
    }
  }
}
</style>
